<?php


namespace catchAdmin\apipatient\controller;


use app\BaseController;
use app\common\model\BaseModel;
use app\common\model\BindDiseasePath;
use app\common\model\DiseasePatientTask;
use app\common\model\DiseasePatientTaskDetail;
use app\Request;
use catcher\base\CatchRequest;
use catcher\CatchResponse;
use think\exception\ValidateException;

class DiseasePath extends BaseController
{
    public function index(Request $request): \think\response\Json
    {
        $result = (new DiseasePatientTask())->getListByPatientId($request->userInfo["patientId"]);
        return json($result);
    }

    public function processList(Request $request): \think\response\Json
    {
        $taskId = $request->param("task_id", "", "string");
        if (empty(trim($taskId))) {
            throw new ValidateException("任务id不能为空");
        }
        $result = (new DiseasePatientTaskDetail())->getProcessList($taskId);
        return CatchResponse::success($result);
    }

    public function getLatestTask(Request $request): \think\response\Json
    {
        $patientId = $request->userInfo["patientId"];

        $result = (new DiseasePatientTaskDetail())->getLatestTask($patientId);

        return CatchResponse::success($result ?? []);
    }

    public function getMyPath(Request $request): \think\response\Json
    {
        $patientId = $request->userInfo["patientId"];
        $result = (new BindDiseasePath())->getLists($patientId);
        return CatchResponse::success($result);
    }

    public function getMyPathDetail(CatchRequest $request): \think\response\Json
    {

        $diseaseId = $request->param("disease_id", "", "string");
        if (empty($diseaseId)) {
            throw new ValidateException("随访路径ID");
        }
        $result = (new DiseasePatientTaskDetail())->getListByDiseaseId($diseaseId);
        return CatchResponse::success($result);

    }

}